/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import TableView.DesignationWeightageTable;
import data.Designation;
import data.Designationweightage;
import data.Sections;
import java.util.List;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.table.TableModel;
import util.BaseDAO;

/**
 *
 * @author Hùng
 */
public class DesignationDAO extends BaseDAO {

    public List<Designation> getAllDesignation() {
        String hql = "from Designation";
        List<Designation> ldesign = executeHQLQuery(hql);
        return ldesign;
    }

    public Designation getDesignationbyDesignation(String tmpdesign) {
        String hql = "from Designation a where a.designation = '" + tmpdesign + "'";
        List<Designation> ldesign = executeHQLQuery(hql);
        if (ldesign.size() == 0) {
            return null;
        }

        return ldesign.get(0);
    }

  

    public Designation getDesignationbyDidDesign(String iddesign) {
        String hql = "from Designation a where a.designationid = '" + iddesign + "'";
        List<Designation> ldesign = executeHQLQuery(hql);
        if (ldesign.size() == 0) {
            return null;
        }
        return ldesign.get(0);
    }
    //hieu
    public ComboBoxModel getComboBox() {
		DefaultComboBoxModel model = new DefaultComboBoxModel();
		model.addElement("-----None-----");
		for (Designation ds : getAllDesignation()) {
			model.addElement(ds.getDesignationid());
		}
		return model;
	}

	public TableModel showTableDesignationWeightage() {

		DesignationWeightageTable model = new DesignationWeightageTable(getALLDesignationWeightage());
		return model;
	}

	private List<Designationweightage> getALLDesignationWeightage() {
		String hql = "from Designationweightage";
		List<Designationweightage> ldesign = executeHQLQuery(hql);
		return ldesign;
	}
}
